import React, { useState, useLayoutEffect, useEffect, PureComponent, forwardRef, useContext, createContext, useReducer, memo, useCallback, useMemo, useRef, useImperativeHandle } from 'react'
export default function Test() {
  const [counter, setCounter] = useState(10)
  useLogLife('Test')
  return (
    <>
      <div> 此时的值：{counter}</div>
      <hr />
      <button onClick={() => setCounter(counter + 1)}>点击</button>
      <hr />
      <Home></Home>
    </>
  )
}

const Home = props => {
  useLogLife('home')
  return 'Home'
}
// 1.自定义hook必须以use开头，普通函数不能使用
function useLogLife(name) {
  useEffect(() => {
    console.log(`${name}被创建了`)

    return () => {
      console.log(`${name}被销毁了`)
    }
  }, [])
}
